package com.wang.controller;

import com.wang.luntan.common.web.controller.BaseController;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
 * 这个是不需要登录的请求;
 *
 * <pre>
 * 这里面存储的是登录后的页面
 * </pre>
 * */
@Controller
@RequestMapping(value = "/back/adminsBack/")
@Log4j2
public class MainController extends BaseController {
    /**
     * 退出
     * @param request   请求对象
     * @param response  响应对象
     */
    @RequestMapping("/logout")
    public String logout(HttpServletRequest request, HttpServletResponse response){
        /* 登录的时候怎么做,退出的时候就怎么做 */
        HttpSession session = request.getSession();
        /* 删除 */
        session.removeAttribute("adminsSess");
        session.removeAttribute("lastLoginTime");
        String info = "退出成功";
        session.setAttribute("info", info);
        /* 跳转到登录页面 */
        return "redirect:/noLogin/adminsLogin";
    }

    /**
     * 欢迎页面
     */
    @RequestMapping("/welcome")
    public String welcome(){
        log.info("==welcome==");
        return "/back/admins/welcome";
    }

    /**
     * 打开登录页面
     */
    @RequestMapping("/main")
    public String main(){
        log.info("==main==");
        return "/back/admins/main";
    }
}
